package br.com.fidalgotecnologia.layar.json;

import org.json.JSONException;
import org.json.JSONObject;

import br.com.fidalgotecnologia.layar.entity.Layer;

public class LayerJson {
	private static LayerJson instance;
	
	public static LayerJson getInstance() {
		if(instance == null){
			instance = new LayerJson();
		}
		return instance;
	}
	
	public JSONObject toObject(Layer layer){
		JSONObject layarJson = new JSONObject();
		try {
			layarJson.put("layer", layer.getLayer());
			layarJson.put("hotspots", HotSpotJsonArray.getInstance().toArray(layer.getHotSpot()));
			layarJson.put("errorCode", layer.getErrorCode());
			layarJson.put("errorString", layer.getErrorString());
			layarJson.put("nextPageKey", layer.getNextPageKey());
			layarJson.put("morePages", layer.isMorePages());
			layarJson.put("radius", layer.getRadius());
			layarJson.put("refreshInterval", layer.getRefreshInterval());
			layarJson.put("refreshDistance", layer.getRefreshDistance());
			layarJson.put("fullRefresh", layer.isFullRefresh());
			layarJson.put("nextPageKey", layer.getNextPageKey());
			layarJson.put("actions", ActionJsonArray.getInstance().toArray(layer.getActions()));
			layarJson.put("showMessage", layer.getShowMessage());
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return layarJson;
	}

}
